package beans;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import tools.DBManager;

public class AssembleList {
	private ArrayList<AssembleBean> components = new ArrayList<AssembleBean>();;
	private int productID;
	
	private Connection conn = null;
	private Statement stmt = null;
	private ResultSet rs = null;
	
	public AssembleList(){
		
	}

	public ArrayList<AssembleBean> getComponents() {
		return components;
	}

	public void setComponents(ArrayList<AssembleBean> components) {
		this.components = components;
	}

	public int getProductID() {
		return productID;
	}

	public void setProductID(int productID) {
		this.productID = productID;
	}
	
	public boolean initial(int productID){
		//set productID
		setProductID(productID);
		
		try{
			conn = DBManager.getConnection();
			stmt = DBManager.getStatement(conn);
			String sqlCmd = String.format("SELECT * FROM t_assemble WHERE t_assemble.ProductID= %d ", productID);
			rs = stmt.executeQuery(sqlCmd);
			
			while(rs.next()){
				AssembleBean assemble = new AssembleBean();
				assemble.setComponentID(rs.getInt("ComponentID"));
				assemble.setComponentNO(rs.getInt("Quantity"));
				
				components.add(assemble);
			}			
		}catch(Exception e){
			
		}finally{
			DBManager.close(rs);
			DBManager.close(stmt);
			DBManager.close(conn);
		}
		
		return false;
	}
}
